home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / comm / revrdist.sit / RevRdist / RevRdist src / syserr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-02  |  1.3 KB  |  58 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Routine to look up the system error message corresponding to a
  3.  * result code
  4.  */
  5. static    Str255    eText;
  6. #define    ERRSTR    999                    /* Resource id of errlist STR# */
  7.  
  8. #include <MacTypes.h>
  9. #include <MacProto.h>
  10. #include <C_Config.h>
  11. StringPtr        syserrlist (OSErr);
  12.  
  13.  
  14.  
  15. /*
  16.  *=========================================================================
  17.  * syserrlist (n) - look up text for result code n
  18.  *    returns a pointer to a static Str255 containing the text
  19.  *=========================================================================
  20.  */
  21. StringPtr
  22. syserrlist (n)
  23. OSErr    n;
  24. {
  25.     Integer    i, j;
  26.     Longint    l;
  27.     int        len;
  28.  
  29.     for (i = 1;;i++)
  30.     {
  31.         /*
  32.          * The ERRSTR STR# resource should contain strings of the form:
  33.          * "-nnn:Error text"
  34.          * We search through all the STR#'s looking for one with a
  35.          * nnn which matches the error we're looking for.
  36.          */
  37.         eText[0] = 0;
  38.         GetIndString (eText, ERRSTR, i);
  39.         len = eText[0];
  40.         if (len == 0)
  41.             break;                    /* end of STR# or couldn't get rsrc */
  42.         for (j = 2; j < 6; j++)
  43.             if (eText[j] == ':' || eText[j] == ' ')
  44.                 break;
  45.         eText[0] = j - 1;                /* shorten string for StringToNum */
  46.         StringToNum (eText, &l);
  47.         eText[0] = len;
  48.         if (l == n)
  49.             break;
  50.     }
  51.     /*
  52.      * We either found the message, or we didn't
  53.      * In the latter case, we just return the number as text
  54.      */
  55.     if (eText[0] == 0)
  56.         NumToString ((long) n, eText);
  57.     return eText;
  58. }